package com.flycat.dto.query;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * 分页查询条件类
 * @Author yalei.chen
 * @Date 2017/9/24
 * @Since JDK 1.8
 */
@ApiModel(value="分页查询条件")
public class PageQuery extends CommonQuery implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final int DEF_COUNT = 10;

    //每页多少条数据
    @ApiModelProperty(value="每页个数")
    protected int pageSize = 20;
    //页码
    @ApiModelProperty(value="页数")
    protected int pageNo = 1;

    /**
     * 是否进行分页
     */
    @ApiModelProperty(value="是否进行分页 true:分页/false:不分页")
    protected boolean paged = true;

    /**
     * 获得页码,使不超过最大页数
     */
    public int getPageNoReasonable() {
        if (pageNo < 1) {
            pageNo = 1;
        }

        return pageNo;
    }


    /**
     * 每页几条数据
     */
    public int getPageSizeReasonable() {
        if (pageSize < 1){
            pageSize = DEF_COUNT;
        }
        return pageSize;
    }

    public int getPageSize() {
        return pageSize;
    }

    public PageQuery setPageSize(int pageSize) {
        this.pageSize = pageSize;
        return this;
    }

    public int getPageNo() {
        return pageNo;
    }

    public PageQuery setPageNo(int pageNo) {
        this.pageNo = pageNo;
        return this;
    }

    public boolean isPaged() {
        return paged;
    }

    public void setPaged(boolean paged) {
        this.paged = paged;
    }

    @Override
    public String toString() {
        return "PageQuery{" +
                "pageSize=" + pageSize +
                ", pageNo=" + pageNo +
                ", paged=" + paged +
                "} " + super.toString();
    }
}
